<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge"/>
    <title>ECPAY-登录</title>
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport"/>
    <link rel="stylesheet" th:href="@{/libs/bootstrap/bootstrap.min.css}"/>
    <link rel="stylesheet" th:href="@{/libs/font-awesome/font-awesome.min.css}"/>
    <link rel="stylesheet" th:href="@{/libs/iCheck/square/blue.css}"/>
    <link rel="stylesheet" th:href="@{/libs/validate/validate.css}"/>
    <link rel="stylesheet" th:href="@{/css/common.css}"/>
    <link rel="stylesheet" th:href="@{/css/login.css}"/>
</head>
<body>
<div th:replace="home/fragments/top :: top"></div>
<div class="login-content">
    <div class="login-bg"></div>
    <div class="login-box">
        <form id="loginForm" class="login-form">
            <div class="login-title">用户登录</div>
            <div class="form-group has-feedback">
                <input type="text" name="username" class="form-control" placeholder="Account"
                       max="14" min="3" required="必填项" nochinese="账号不能为空" autocomplete="off"/>
                <span class="glyphicon glyphicon-envelope form-control-feedback"></span>
            </div>
            <div class="form-group has-feedback">
                <input name="password" type="password" class="form-control" placeholder="Password" require="必填项"
                       nochinese="密码不能包括中文" autocomplete="off"/>
                <span class="glyphicon glyphicon-lock form-control-feedback"></span>
            </div>
            <div class="form-group has-feedback">
                <div class="vcode-content">
                    <input type="text" name="vcode" class="form-control" placeholder="Verification Code"
                           max="14" min="3" required="必填项" nochinese="验证码不能为空" autocomplete="off"/>
                    <span class="glyphicon glyphicon-envelope form-control-feedback"></span>
                </div>
                <button class="btn btn-adn scode" type="button">发送验证码</button>
            </div>
            <div class="form-group has-feedback vcode">
                <div class="vcode-content">
                    <input type="text" name="verification" class="form-control vcode-input" placeholder="验证码"
                           require="必填项" data-position="position-a" autocomplete="off"/>
                    <span class="fa fa-key vcode-icon form-control-feedback"></span>
                </div>
                <img th:src="@{verificationCode}" class="pointer vcode-img"/>
            </div>

            <div class="row">
                <div class="col-xs-8">
                    <div class="checkbox icheck">
                        <label style="padding: 0">
                            <input type="checkbox" id="rememberMe" name="rememberMe" value="0"/> 记住我
                        </label>
                    </div>
                </div>
                <!-- /.col -->
                <div class="col-xs-4">
                    <button id="loginBtn" type="button" class="btn btn-primary btn-block btn-flat">登录</button>
                </div>
                <!-- /.col -->
            </div>
        </form>
    </div>
</div>

<div th:replace="home/fragments/footer :: copyrightLight"></div>

<script th:src="@{/libs/jquery/jquery.min.js}"></script>
<script th:src="@{/libs/bootstrap/bootstrap.min.js}"></script>
<script th:src="@{/libs/layer/layer.js}"></script>
<script th:src="@{/libs/iCheck/icheck.min.js}"></script>
<script th:src="@{/libs/validate/validate.js}"></script>

<script>
    $(function () {
        $('input').iCheck({
            checkboxClass: 'icheckbox_square-blue',
            radioClass: 'iradio_square-blue',
            increaseArea: '20%' // optional
        });

    });
</script>

<script type="text/javascript" th:inline="javascript">
    /*<![CDATA[*/
    ctxPath = /*[[@{/}]]*/ '';
    /*]]>*/

</script>


<script>

    $(function () {
        $(".vcode-img").on('click', function () {
            $(this).attr('src', ctxPath + '/verificationCode?' + Math.floor(Math.random() * 100));
        });
        $("#loginBtn").on('click', function () {
            if (!doValidForm(loginForm)) {
                //没有通过验证
                return;
            }
            $.ajax({
                type: "POST",
                url: ctxPath + "/login",
                data: $(".login-form").serialize(),
                dataType: "json",
                success: function (data) {
                    if (data.code == 200) {
                        layer.msg(data.msg, {
                            offset: '30%',
                            time: 800
                        }, function () {
                            window.location.href = ctxPath + "index";
                        });
                    } else {
                        layer.msg(data.msg, {
                            icon: 2,
                            offset: '30%',
                            time: 2000
                        });
                        $("#verificationCode").click();
                    }
                }
            });
        });

        $(document).keyup(function (event) {
            if (event.keyCode == 13) {
                $("#loginBtn").click();
            }
        });
        var count = 60;
        function set() {
            if (count == 0) {
                $('.scode').removeProp('disabled');
                $('.scode').text('获取验证码');
                count = 60;
            } else {
                $('.scode').text(count + 's');
                $('.scode').prop('disabled');
                count--;

                setTimeout(function(){
                    set()
                }, 1000)

            }

        }
        $('.scode').click(function () {
            var username = $('input[name = username]').val();

            if (null != username && '' != username) {



                // return;
                $.ajax({
                    type: "POST",
                    url: ctxPath + "sys/sms/sendLoginVerifyCode",
                    data: {'phone': username},
                    dataType: "json",
                    success: function (data) {
                        if (data.code == 0) {
                            layer.msg(data.msg, {
                                offset: '30%',
                                time: 800
                            }, function () {
                                // window.location.href = ctxPath + "index";
                                set()
                            });
                        } else {
                            layer.msg(data.msg, {
                                icon: 2,
                                offset: '30%',
                                time: 2000
                            });

                        }
                    }
                });
            } else {
                layer.msg('请先输入账号', {
                    icon: 2,
                    offset: '30%',
                    time: 2000
                });
            }
        });
    })
</script>
</body>
</html>
